package fhp.hlhj.giantfold.activity.orders

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.interfaces.IOrderDetail
import fhp.hlhj.giantfold.javaBean.OrderBean
import fhp.hlhj.giantfold.network.Urls
import fhp.hlhj.giantfold.presenter.OrderDetailPresenter
import kotlinx.android.synthetic.main.activity_order_detail.*

class OrderDetail : BaseActivity(), IOrderDetail {


    private lateinit var presenter:OrderDetailPresenter
    override fun getContentId(): Int = R.layout.activity_order_detail


    override fun initView() {

        presenter= OrderDetailPresenter(this)
        val params = HttpParams()
        params.put("user_id",Contents.userId)
        params.put("id",intent.getStringExtra("oid"))
        presenter.getOrder(params)
    }

    override fun initListener() {

        btExit.setOnClickListener {
            finish()
        }
    }
    override fun showLoading() {
        loadingDialog.show()
    }

    override fun getOrderDetail(orderBean: OrderBean) {
        loadingDialog.dismiss()
        if (orderBean.code==200){
            when(orderBean.data.deposit_status){
                "0"->{
                    "未存入"
                    tv1.visibility= View.VISIBLE
                }
                "1"->{
                    "已存入"
                    tv1.visibility= View.VISIBLE
                    tv2.visibility= View.VISIBLE
                }
                "2"->{
                    "不存入"
                }
                else->{
                    ""
                }
            }
            orderStatus.text=when(orderBean.data.deposit_status){
                "0"->{
                    "未存入"
                }
                "1"->{
                    "已存入"
                }
                "2"->{
                    "不存入"
                }
                else->{
                    ""
                }

            }
            shopName.text=when(orderBean.data.type){
                "0"->{
                    "淘宝"
                }
                "1"->{
                    "天猫"
                }
                else->{
                    ""
                }
            }
            orderNum.text=orderBean.data.order_id
            orderTime.text=orderBean.data.updated_time
            if (orderBean.data.tkjd_sp.equals("1")){
                Glide.with(this).load(orderBean.data.product_pic_url).asBitmap().dontAnimate().placeholder(R.mipmap.placeholdericon).into(orderIcon)
            }else{
                if (orderBean.data.product_name.equals("新人红包")){
                    Glide.with(this).load(R.mipmap.nianhuashouyi_hb).asBitmap().dontAnimate().placeholder(R.mipmap.placeholdericon).into(orderIcon)

                }else{

                    Glide.with(this).load(orderBean.data.pict_url).asBitmap().dontAnimate().placeholder(R.mipmap.placeholdericon).into(orderIcon)
                }
            }
            orderPrice.text=orderBean.data.actual_amount
            orderTittle.text=orderBean.data.product_name
            orderSaveNum.text="￥${orderBean.data.actual_amount}"
        }
    }
}
